import os
import sys
import socket
from functools import wraps
os.environ['HFS']=r'C:\Program Files\Side Effects Software\Houdini 18.5.379'
os.environ['PATH'] = r'C:\Program Files\Side Effects Software\Houdini 18.5.379\bin;%s' % os.environ['PATH']

# import hou

def send(func):
    @wraps(func)
    def wrapper(*args,**kwargs):
        print('log开始 ...',func.__name__)
        ret = func(*args,**kwargs)
        print('log结束 ...')
        return ret
    return wrapper




class CGAI(object):

    def __init__(self):
        super(CGAI, self).__init__()

    def drop(self,*args,**kwargs):
        """
        必须加上*args,**kwargs，因为你无法得知该函数是否会带参数
        :param args:
        :param kwargs:
        :return:
        """
        print('drop:',args,kwargs)
        return self

    def send(self,msg):
        if msg:
        # data={}
            sock=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
            try:
                sock.connect((self.HOST,self.PORT))
                sock.send(str(msg).encode())
                # back=sock.recv(self.BUFFER)
                # if back:
                #     # self.project_info=eval(back.decode('utf8'))
                #     # print(e(self.project_info))
                #     # print(self.project_info)
                #     data=eval(back.decode('utf8'))
            except Exception as request_from_222_ERR:
                print('request failed')
                print(str(request_from_222_ERR))
            finally:
                sock.close()

        return self


    def __getattr__(self, item):
        """
        这个就是当该类实例化后 . 开始读取属性或者调用函数时触发
        :param item:
        :return:
        """
        print('__getattr__',item,type(item))
        return self.drop

    def __call__(self, *args, **kwargs):
        """
        当该类被调用时，get这些事件时
        :param args:
        :param kwargs:
        :return:
        """
        # print('jaja')
        pass

    # def __dir__(self):
    #     print('dir')
    #
    # def __aiter__(self):
    #     print('aiter')
    #
    # def __sub__(self, other):
    #     print('sub')
    #
    # def __subclasscheck__(self, subclass):
    #     print('subclass')
    #
    def __getitem__(self, item):
        """
        这个就是当函数名后接[]要读取内容时调用
        :param item:
        :return:
        """
        print('getitem',item)
        return self
    #
    # def __getattribute__(self, item):
    #     print('getattribute',item)
    # #
    # def __get__(self, instance, owner):
    #     print('get')

    def __class_getitem__(cls, item):
        print(item)
        print("__class_getitem__")

    def __abs__(self):
        print('__abs__')

hou=CGAI()
box1=hou.node("/obj/geo1/box1")
box2=hou.node("/obj/geo1/box2")
box2.setInput(0,box1)
# print(node)

# sn=hou.selectNode()
# print(sn)
# node= sn[0]
# print(node)

#